//
//  ViewController.m
//  homeWorkForNews
//
//  Created by 苗钧豪 on 16/8/3.
//  Copyright © 2016年 苗钧豪. All rights reserved.
//

#import "ViewController.h"
#import "CollectionViewCell.h"
#import "myLayout.h"
#import <AVFoundation/AVFoundation.h>
#import "SelfSizeTool.h"
@interface ViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,JHLayoutDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    _Arr = [NSMutableArray arrayWithObjects:@"奥运会专区",@"体育",@"社会",@"人文",@"科技",@"汽车",@"动物世界",@"奇闻异事",@"军事",@"游戏",@"色情",@"国际",@"国内",@"网络游戏",@"单机游戏",@"网页游戏",@"手机游戏",@"桌游世界",@"制服诱惑", nil];
    myLayout *layout = [[myLayout alloc]init];
    UICollectionView *collectionView = [[UICollectionView alloc]initWithFrame:self.view.bounds collectionViewLayout:layout];
    layout.delegate = self;
    collectionView.delegate = self;
    collectionView.dataSource = self;
    collectionView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:collectionView];
    [collectionView registerNib:[UINib nibWithNibName:@"CollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"1"];
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout height:(CGFloat)height heightForItemIndexPath:(NSIndexPath *)indexPath {
    
    return [SelfSizeTool selfSizeHeightWithString:_Arr[indexPath.row] height:height font:[UIFont systemFontOfSize:17]];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _Arr.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"1" forIndexPath:indexPath];
    cell.newsLabel.text = _Arr[indexPath.row];
    return cell;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
